package com.itboy.mall.ums.memberlevel.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.ums.memberlevel.vo.MallMemberLevelVo;
import com.itboy.mall.ums.memberlevel.bo.MallMemberLevelQueryBo;
import com.itboy.mall.ums.memberlevel.bo.MallMemberLevelAddBo;
import com.itboy.mall.ums.memberlevel.bo.MallMemberLevelEditBo;
import com.itboy.mall.ums.memberlevel.service.IMallMemberLevelService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 会员等级Controller
 *
 * @author itboy
 * @date 2021-08-07
 */
@Validated
@Api(value = "会员等级控制器", tags = {"会员等级管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/memberLevel")
public class MallMemberLevelController extends BaseController {

    private final IMallMemberLevelService iMallMemberLevelService;

    /**
     * 查询会员等级列表
     */
    @ApiOperation("查询会员等级列表")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:list')")
    @GetMapping("/list")
    public TableDataInfo<MallMemberLevelVo> list(@Validated MallMemberLevelQueryBo bo) {
        return iMallMemberLevelService.queryPageList(bo);
    }

	/**
	 * 会员等级列表
	 */
	@ApiOperation("会员等级列表")
	@GetMapping("/memberLevelList")
	public AjaxResult<List<MallMemberLevelVo>> memberLevelList(MallMemberLevelQueryBo bo) {
		List<MallMemberLevelVo> list = iMallMemberLevelService.queryList(bo);
		return AjaxResult.success(list);
	}

    /**
     * 导出会员等级列表
     */
    @ApiOperation("导出会员等级列表")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:export')")
    @Log(title = "会员等级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallMemberLevelVo> export(@Validated MallMemberLevelQueryBo bo) {
        List<MallMemberLevelVo> list = iMallMemberLevelService.queryList(bo);
        ExcelUtil<MallMemberLevelVo> util = new ExcelUtil<MallMemberLevelVo>(MallMemberLevelVo.class);
        return util.exportExcel(list, "会员等级");
    }

    /**
     * 获取会员等级详细信息
     */
    @ApiOperation("获取会员等级详细信息")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallMemberLevelVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallMemberLevelService.queryById(id));
    }

    /**
     * 新增会员等级
     */
    @ApiOperation("新增会员等级")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:add')")
    @Log(title = "会员等级", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallMemberLevelAddBo bo) {
        return toAjax(iMallMemberLevelService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改会员等级
     */
    @ApiOperation("修改会员等级")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:edit')")
    @Log(title = "会员等级", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallMemberLevelEditBo bo) {
        return toAjax(iMallMemberLevelService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除会员等级
     */
    @ApiOperation("删除会员等级")
    @PreAuthorize("@ss.hasPermi('mall:memberLevel:remove')")
    @Log(title = "会员等级" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallMemberLevelService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
